<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css"
          media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css" media="all">
    <style>
        thead tr th {
            text-align: center !important;
        }

        tr td {
            text-align: center !important;
        }

    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body layui-form">
                    <%-- 查询条件设置 --%>
                    <div class="layui-container layui-form-item" style="padding-bottom: 50px">
                        <div class="layui-col-md12">
<%--                            <div class="layui-col-md3">--%>
<%--                                <div class="layui-col-sm3" style="line-height: 38px">申请人:</div>--%>
<%--                                <div class="layui-col-sm8">--%>
<%--                                    <input type="text" name="fullName"   placeholder="请输入申请人" autocomplete="off" class="layui-input"/>--%>
<%--                                </div>--%>
<%--                            </div>--%>
<%--                            <div class="layui-col-md3">--%>
<%--                                <div class="layui-col-sm3" style="line-height: 38px">身份证:</div>--%>
<%--                                <div class="layui-col-sm8">--%>
<%--                                    <input type="text" name="idCard"   placeholder="请输入身份证" autocomplete="off" class="layui-input"/>--%>
<%--                                </div>--%>
<%--                            </div>--%>

<%--                            <div class="layui-col-md3">--%>
<%--                                <div class="layui-col-sm3" style="line-height: 38px">手机号码:</div>--%>
<%--                                <div class="layui-col-sm8">--%>
<%--                                    <input type="text" name="phoneNumber"   placeholder="请输入手机号码" autocomplete="off" class="layui-input"/>--%>
<%--                                </div>--%>
<%--                            </div>--%>
<%--                            <div class="layui-col-md3">--%>
<%--                                <div class="layui-col-sm3" style="line-height: 38px">手机号码:</div>--%>
<%--                                <div class="layui-col-sm8">--%>
<%--                                    <input type="text" name="phoneNumber"   placeholder="请输入手机号码" autocomplete="off" class="layui-input"/>--%>
<%--                                </div>--%>
<%--                            </div>--%>

                            <div  class="layui-col-md3" style="margin-top: 10px">
                                <div class="layui-col-sm3" style="line-height: 38px">贷款名称:</div>
                                <div class="layui-col-sm8">
                                    <select name="productTypeId" class="city" data-flag="2" id="productTypeId">
                                        <c:forEach items="${loadData}" var="list">
                                            <option value="${list.id}">${list.loanName}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                            <div  class="layui-col-md3" style="margin-top: 10px">
                                <div class="layui-col-sm3" style="line-height: 38px">申请时间:</div>
                                <div class="layui-col-sm8">
                                    <input class="layui-input"   placeholder="请选择时间范围" name="yyTime" id="laydate-cn" autocomplete="off">
                                </div>
                            </div>
                            <div  class="layui-col-md3" style="margin-top: 10px">
                                <div class="layui-col-sm3" style="line-height: 38px">审核结果:</div>
                                <div class="layui-col-sm8">
                                    <select name="handleResult" class="city" data-flag="2" id="selecthandleResult">
                                        <option value="3">待处理</option>
                                        <option value="1">预约成功</option>
                                        <option value="2">预约失败</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-col-md3" style="margin-top: 10px">
                                <div class="layui-col-sm9 layui-col-sm-offset3">
                                    <button class="layui-btn layuiadmin-btn-list" lay-submit
                                            lay-filter="LAY-app-contlist-search" id="selectbtn">查询
                                    </button>
                                </div>
                            </div>

                        </div>
                    </div>

                    <%-- 数据展示 --%>
                    <table class="layui-table" id="table" lay-filter="table"></table>
                    <script type="text/html" id="toolbar">
                        <div class="layui-btn-container">
                            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="delete">详情</a>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script>




    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'table'], function () {
        var $ = layui.$, layer = layui.layer, form = layui.form,
            element = layui.element, laydate = layui.laydate, table = layui.table;
        form.render('select');
        element.render();
        laydate.render({
            elem: '#laydate-cn',
            range: '~'
        });

        table.render({
            elem: '.layui-table',
            url: '/bankloanapplyrecord/listDate',
            page: true,
            toolbar: '#table-operate-tool',
            request: {
                pageName: 'current', //页码的参数名称，默认：page
                limitName: 'size' //每页数据量的参数名，默认：limit
            },
            cols: [[
                // {field: 'fullName', title: '申请人',width: 120,fixed: 'left'},
                // {field: 'cardTypeId', title: '身份证类型',width: 120},
                // {field: 'idCard', title: '身份证',width: 200},
                // {field: 'sex', title: '性别',width: 60,templet:function (d) {
                //         if(d.sex!=null && d.sex!=''){
                //             if(d.sex==1){
                //                 return "女";
                //             }else {
                //                 return "男"
                //             }
                //         }else {
                //             return "";
                //         }
                //     }},
                // {field: 'phoneNumber', title: '手机号码',width: 120},
                // {field: 'loanAmount', title: '贷款金额',width: 200,templet:function (d) {
                //         if(d.loanAmount!=null && d.loanAmount!=''){
                //             return d.loanAmount.toLocaleString();
                //         }
                //     }},
                // {field: 'subBranchId', title: '预约支行',width: 200},
                // {field: 'subscribeTime', title: '预约时间',width: 200,templet: function (d) {
                //         if(d.subscribeTime != null && d.subscribeTime != ""){
                //             return layui.util.toDateString(d.subscribeTime, 'yyyy-MM-dd HH:mm');
                //         }else{
                //             return "";
                //         }
                //     }},
                {field: 'productTypeId',title: '贷款名称',width: 240},
                {field: 'applyTime', title: '申请时间',width: 240,templet:function (d) {
                        if(d.applyTime != null && d.applyTime != ""){
                            return layui.util.toDateString(d.applyTime, 'yyyy-MM-dd HH:mm');
                        }else{
                            return "";
                        }
                    }},
                {field: 'lastOperateTime', title: '最后操作时间',width: 240,templet:function (d) {
                        if(d.lastOperateTime != null && d.lastOperateTime != ""){
                            return layui.util.toDateString(d.lastOperateTime, 'yyyy-MM-dd HH:mm');
                        }else{
                            return "";
                        }
                    }},
                {field: 'operator', title: '最后操作人',width: 240},
                {field: 'handleResult',title: '审核结果',width:240,templet:function (d) {
                        if(d.handleResult != null && d.handleResult != ""){
                           if(d.handleResult==1){
                               return "预约成功";
                           }if(2==d.handleResult){
                               return "预约失败"
                           }else {
                               return  "待处理"
                           }
                        }else {
                            return "";
                        }
                    }},
                {title: '操作', templet: '#toolbar',fixed: 'right'}
            ]],
            skin: "row",
            even: true,
            size: "lg"
        });

        var active = {
            delete: function (id) {
                window.location.href="/bankloanapplyrecord/detail?id="+id;
            },
            adopt:function(id,status){
                $.ajax({
                    url: "/bankloanapplyrecord/updateHandResult",
                    data: {'id': id,'status':1},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.code==200) {
                            layer.msg(data.msg);
                            setTimeout(function () {
                                window.location.reload();
                            }, 1000)
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                })
            },
            exportThis: function (bid, orderType, payType, orderStatus, phone, orderCode, payCode, queryTime) {
                window.location.href = encodeURI("/export/handleExportOrder?queryTime=" + queryTime + "&payCode=" + payCode + "&orderCode=" + orderCode + "&phone=" + phone + "&payType=" + payType
                    + "&payType=" + payType + "&bid=" + bid + "&orderType=" + orderType + "&orderStatus=" + orderStatus);
            }
        };
        //导出事件触发
        $(".exportThis").on('click', function () {
            var exportThis = $(this).data('type');
            var bid = $('select[name="bid"]').find('option:selected').val();
            var orderType = $('select[name="orderType"]').find('option:selected').val();
            var payType = $('select[name="payType"]').find('option:selected').val();
            var orderStatus = $('select[name="orderStatus"]').find('option:selected').val();
            var phone = $('input[name="phone"]').val();
            var orderCode = $('input[name="orderCode"]').val();
            var payCode = $('input[name="payCode"]').val();
            var queryTime = $('input[name="queryTime"]').val();
            active[exportThis] && active[exportThis].call(this, bid, orderType, payType, orderStatus, phone, orderCode, payCode, queryTime);
        });

        table.on('edit(table)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            console.log(".....................")
            console.log(obj.value); //得到修改后的值
            console.log(obj.field); //当前编辑的字段名
            console.log(obj.data); //所在行的所有相关数据

            //---
            $.ajax({
                url: "/chickenOrder/handleChickenBonusDayEdit",
                data: {"id": obj.data.id, "day": obj.data.day, "couponQty": obj.data.couponQty, "qty": obj.data.qty},
                dataType: "json",
                type: "post",
                success: function (data) {
                    console.log(data)
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1});
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                }
            })
            //---

        });

        table.on('toolbar(table)', function (obj) {
            if (obj.event === 'add') {
                layer.open({
                    type: 2,
                    title: "新增鸡舍",
                    area: ['700px', '500px'],
                    content: "/chickenRepository/chickenRepositoryAdd",
                });
            }
        });

        //监听事件
        table.on('tool(table)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'delete') {// 删除
                active[layEvent] && active[layEvent].call(this, data.id, data.title);
            } else if (layEvent === 'adopt') {// 更改处理结果
                if(data.handleResult==1 || data.handleResult==2){
                    return;
                }
                active[layEvent] && active[layEvent].call(this, data.id, data.handleResult);
            }
        });

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('table', {
                where: field
            });
        });


        //缓存当前操作的是哪个表格的哪个tr的哪个td
        $(document).off('mousedown', '.layui-table-grid-down').on('mousedown', '.layui-table-grid-down', function (event) {
            //直接记录td的jquery对象
            table._tableTrCurrr = $(this).closest('td');
        });

        //给弹出的详情里面的按钮添加监听级联的触发原始table的按钮的点击事件
        $(document).off('click', '.layui-table-tips-main [lay-event]').on('click', '.layui-table-tips-main [lay-event]', function (event) {
            var elem = $(this);
            var tableTrCurrr = table._tableTrCurrr;
            if (!tableTrCurrr) {
                return;
            }
            var layerIndex = elem.closest('.layui-table-tips').attr('times');
            layer.close(layerIndex);
            table._tableTrCurrr.find('[lay-event="' + elem.attr('lay-event') + '"]').first().click();
        });
    })
</script>
</body>
</html>
